package com.seedwill.common.exception;

import java.util.Locale;
import java.util.ResourceBundle;

/**
 *  通用异常
 *  
 *  common exception
 * 
 * @author kdyOi
 *
 */
public class SeedWillException extends RuntimeException {
	
	//getBundle(baseName, Locale.getDefault(), this.getClass().getClassLoader()), 
	private  ResourceBundle BUNDLE = ResourceBundle.getBundle(ExceptionMessageConfig.message_location, Locale.getDefault(), this.getClass().getClassLoader());

	/**
	 * 
	 */
	private static final long serialVersionUID = 6997683238839008788L;
	
	/**
	 * 错误代码
	 */
	private String errCode;
	
	/**
	 * 严重程度
	 */
	private ExceptionSeverity severity;

	public SeedWillException() {
	}

	public SeedWillException(String message) {
		super(message);
	}

	public SeedWillException(String message, Throwable cause) {
		super(message, cause);
	}

	public SeedWillException(Throwable cause) {
		super(cause);
	}

	public SeedWillException(String message, String errCode) {
		super(message);
		this.errCode = errCode;
	}

	public SeedWillException(String message, String errCode, Throwable cause) {
		super(message, cause);
		this.errCode = errCode;
	}

	public String getErrCode() {
		return errCode;
	}

	public void setErrCode(String errCode) {
		this.errCode = errCode;
	}
	
	public String getErrorMessage(){
		String errMsg = null;
		if(null != errCode){
			errMsg = BUNDLE.getString(errCode);
		}
		return errMsg;
	}
	
	public String getMergedMessage(String sep){
		String errMsg = null;
		if(null != errCode){
			errMsg = (null == this.getMessage()) ? "" : ((null == this.getMessage() + sep) ? "" : (sep + BUNDLE.getString(errCode)));
		}
		return errMsg;
	}

	public ExceptionSeverity getSeverity() {
		return severity;
	}

	public void setSeverity(ExceptionSeverity severity) {
		this.severity = severity;
	}
}
